package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.StrategyLikeMapper;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.UserProfilesQueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StrategyServiceImpl implements IStrategyService{
    @Autowired
    private StrategyMapper strategyMapper;
    @Autowired
    private StrategyLikeMapper likeMapper;

    public List<Strategy> listAll() {
        return strategyMapper.selectAll();
    }

    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId() != null) {
            strategyMapper.updateByPrimaryKey(strategy);
        } else {
            strategyMapper.insert(strategy);
        }
    }

    public Strategy get(Long strategyId) {
        Strategy strategy = strategyMapper.selectByPrimaryKey(strategyId);
        int likes = likeMapper.countStrategyLike(strategy.getId());
        strategy.setLikeNum(likes);
        return strategy;
    }

    public Map<String, Object> getCounts(String keyword) {
        return strategyMapper.getCounts(keyword);
    }

    public PageInfo queryforStrategies(UserProfilesQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Strategy> strategies =strategyMapper.selectStrategiesByUserId(qo);
        return  new PageInfo(strategies);
    }

    public Boolean queryforStrategy(UserProfilesQueryObject qo) {
        strategyMapper.selectByuserIdandstrategyId();
        return null;
    }

    public void saveStrategies(UserProfilesQueryObject qo) {

    }

    public PageInfo<Strategy> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(),true,false,null);
        List<Strategy> list = strategyMapper.selectForList(qo);
        return new PageInfo(list);
    }
}
